﻿using System;
using System.ComponentModel;
using System.Linq;
using ProjectEuler.Linq;

namespace ProjectEuler.Problems
{
    [EulerProblem(25, 4782)]
    [Description("What is the first term in the Fibonacci sequence to contain 1000 digits?")]
    internal sealed class Problem025 : EulerProblem
    {
        private const Double Phi = 1.61803398874989484820458683436563811772030917980576;

        private static readonly Double PhiLog10 = Math.Log10(Phi);
        private static readonly Double Sqrt5Log10 = Math.Log10(5) / 2;

        public override Object Solve()
        {
            return Integers.From(1).First(n => GetFibDigitCount(n) == 1000);
        }

        private static Int32 GetFibDigitCount(Int64 n)
        {
            return 1 + (Int32)((n * PhiLog10) - Sqrt5Log10);
        }
    }
}
